package map;

import org.junit.Test;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class HashMapdemo1 {
    //第一种遍历方式
    @Test
    public void method1(){
        Map<String,Student> map=new HashMap<>();
        map.put("1号",new Student(18,"张三"));
        map.put("2号",new Student(18,"李四"));
        map.put("3号",new Student(18,"王五"));
        map.put("4号",new Student(18,"赵六"));

        Set<String> set = map.keySet();
        for (String temp:set){
            Student student=map.get(temp);
            System.out.println(student);
        }
    }
    //第二种遍历方式
    @Test
    public void method2(){
        Map<String,Student> map=new HashMap<>();
        map.put("1号",new Student(18,"张三"));
        map.put("2号",new Student(18,"李四"));
        map.put("3号",new Student(18,"王五"));
        map.put("4号",new Student(18,"赵六"));

        Set<Map.Entry<String, Student>> entries = map.entrySet();
        System.out.println(entries);
        for (Map.Entry<String,Student> entry:entries){
            System.out.println(entry.getClass());
            System.out.println(entry.getKey()+"---"+entry.getValue());
        }
    }
}
